package org.example.seata.common.rabbitmq.config;

import org.example.seata.common.rabbitmq.constant.ExchangeQueueRoutingKey;
import org.example.seata.common.rabbitmq.constant.QueueArgument;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hzq
 * @date 2021/11/29 17:31
 */
@Configuration
public class RabbitQueueConfiguration {

    @Bean
    public Queue orderDelayDirectQueue() {
        return QueueBuilder.durable(ExchangeQueueRoutingKey.ORDER_DELAY_DIRECT_QUEUE)
                // 消息10分钟过期
                .withArgument(QueueArgument.X_MESSAGE_TTL, 600000)
                // 死信交换器
                .withArgument(QueueArgument.X_DEAD_LETTER_EXCHANGE, ExchangeQueueRoutingKey.ORDER_DIRECT_EXCHANGE)
                // 死信路由键
                .withArgument(QueueArgument.X_DEAD_LETTER_ROUTING_KEY, ExchangeQueueRoutingKey.ORDER_DIRECT_ROUTING_KEY)
                .build();
    }

    @Bean
    public Queue orderDirectQueue() {
        return QueueBuilder.durable(ExchangeQueueRoutingKey.ORDER_DIRECT_QUEUE).build();
    }

    @Bean
    public Queue orderPayDirectQueue() {
        return QueueBuilder.durable(ExchangeQueueRoutingKey.ORDER_PAY_DIRECT_QUEUE).build();
    }
}
